@echo off
color 2e
title=F1C100S/F1C200S  download  all .bin

echo ============= START =============
echo 即将按顺序烧录：boot0 -> iboot -> logo -> app -> ID
echo.


:: 2. iboot
echo ====== download iboot ======
cd "%~dp0xfel-windows-v1.3.2"
xfel spinor write 0x50000 "%~dp0transfusion_Iboot_Debug.bin"
if %errorlevel% neq 0 (
    echo iboot fail
    pause
    exit /b 1
)
echo iboot success
echo.

:: 3. 烧录logo
echo ======download logo ======
cd "%~dp0xfel-windows-v1.3.2"
xfel spinor write 0x6000 "%~dp0djyos-logo.bmp"
if %errorlevel% neq 0 (
    echo logo fail
    pause
    exit /b 1
)
echo logo success
echo.

:: 4. 烧录app
echo ====== download app ======
cd "%~dp0xfel-windows-v1.3.2"
xfel spinor write 0xD0000 "%~dp0transfusion_App_Debug\transfusion_App_Debug.bin"
if %errorlevel% neq 0 (
    echo app fail
    pause
    exit /b 1
)
echo app success
echo.

:: 5. 烧录ID
echo ====== download ID ======
set /p DEVICE_ID=Enter an eight-digit ID
if not defined DEVICE_ID (
    echo error: ID is null
    pause
    exit /b 1
)
echo %DEVICE_ID% > "%~dp0ID.txt"
cd "%~dp0xfel-windows-v1.3.2"
xfel spinor write 0x1FFFFF8 "%~dp0ID.txt"
if %errorlevel% equ 0 (
    echo download ID success，new ID：%DEVICE_ID%
) else (
    echo download ID fail
    pause
    exit /b 1
)
echo.

:: 1. 烧录boot0
echo ======download  boot0 ======
cd "%~dp0xfel-windows-v1.3.2"
xfel spinor write 0x00000 "%~dp0boot0.bin"
if %errorlevel% neq 0 (
    echo boot0 fail
    pause
    exit /b 1
)
echo  boot0 success
echo.


echo =============over =============
echo Exit in three seconds
TIMEOUT /T 3